import pyttsx3
from libbase import singleton

@singleton
class TextToSpeech:
    def __init__(self) -> None:
        self.init()
        self.counter = 0
    def init(self):
        self.engine = pyttsx3.init()
    def say(self, str):
        self.engine.say(str)
        self.engine.runAndWait()
    def setWordPerMinute(self, wordPerMinute):
        self.engine.setProperty('rate', wordPerMinute)
    def setEnglish(self, isEnglish):
        if isEnglish:
            self.engine.setProperty("voice", "en")
        else:
            self.engine.setProperty("voice", "zh")
